#include "glosor.h"


namespace doa14
{
	glosor::glosor()
	{
	}


	glosor::~glosor()
	{
	}

	void glosor::add(string word, string translation)
	{
		vg.push_back(glosa(word, translation));
	}

	void glosor::remove(string word)
	{
		vector<vector<glosa>::iterator> vgremove;
		int instances = 0;
		for (vector<glosa>::iterator it = vg.begin(); it < vg.end(); it++)
		{
			if ((*it) == word)
			{
				instances++;
				vgremove.push_back(it);
			}
		}

		for (unsigned int i = 0; i < vgremove.size(); i++)
		{
			vg.erase(vgremove[i]);
		}
		cout << "Removed " << instances << " instance(s) of word " << word << endl;
	}

	void glosor::list()
	{
		for (unsigned int i = 0; i < vg.size(); i++)
		{
			cout << vg[i] << endl;
		}
	}

	void glosor::test()
	{
		int correctAnswers = 0;
		string input;
		for (unsigned int i = 0; i < vg.size(); i++)
		{
			cout << vg[i].getWord() << " - ";
			getline(cin, input);
			if (input == vg[i].getTranslation())
			{
				correctAnswers++;
			}
		}
		cout << endl;
		cout << "Correct Answers: " << correctAnswers << endl;
	}
}